<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('渠道商管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                        	<li class="select-time">
                                <p>创建时间：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                            </li>
                            <li>
                                <p>渠道名称：</p>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <p>推广员：</p>
                                <input type="text" name="promoterId"/>
                            </li>
                            <li>
                                <p>后台账号：</p>
                                <input type="text" name="loginName"/>
                            </li>
                            <li>
                                <p>渠道类型：</p>
                                <select name="model" th:with="type=${@dict.getType('cwsk_channel_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>状态 :</p>
                                <select name="enabled" th:with="type=${@dict.getType('cwsk_channel_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>合作状态 :</p>
                                <select name="cooperaState" th:with="type=${@dict.getType('cwsk_coopera_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="cwsk:channel:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="cwsk:channel:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="cwsk:channel:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('cwsk:channel:edit')}]];
        var removeFlag = [[${@permission.hasPermi('cwsk:channel:remove')}]];
        var prefix = ctx + "cwsk/channel";
        var channel_type = [[${@dict.getType('cwsk_channel_type')}]];
        var special_power = [[${@dict.getType('cwsk_special_power')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "渠道商管理",
                sortName: "createTime",
                sortOrder: "desc",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id',
                    title : '编号',
                    visible: false,
                    align: 'center',
                    sortable: true
                },
                {
                    field : 'createTime', 
                    title : '创建时间',
                    align: 'center',
                    sortable: true,
                },
                {
                    field : 'name', 
                    title : '渠道商简称',
                    align: 'center'
                },
                {
                    field : 'mobile', 
                    title : '手机号',
                    align: 'center'
                },
                {
                    field : 'contact', 
                    title : '联系人',
                    align: 'center'
                },
                {
                    field : 'userId', 
                    title : '后台帐号',
                    align: 'center'
                },
                {
                    field : 'promoterId', 
                    title : '推广员',
                    align: 'center'
                },
                {
                    field : 'acronym', 
                    title : '字母缩写',
                    align: 'center'
                },
                {
                    field : 'subUser', 
                    title : '子账户',
                    align: 'center'
                },
                {
                    field : 'model', 
                    title : '渠道商类型',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(channel_type, value);
                    }
                },
                {
		        	visible: editFlag == 'hidden' ? false : true,
		        	title: '状态',
		        	align: 'center',
		        	formatter: function (value, row, index) {
		        		return statusTools(row);
		        	}
		        },
                {
                    field : 'subUser', 
                    align: 'center',
                    title : '创建子用户',
                   	formatter: function(value, row, index) {
                       return $.table.selectDictLabel(special_power, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        
        /* 用户状态显示 */
		function statusTools(row) {
		    if (row.enabled == 1) {
    			return '<i class=\"fa fa-toggle-on text-navy fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-off text-danger fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
    		}
		}
		
		/* 用户管理-停用 */
		function disable(channelId) {
			$.modal.confirm("确认要禁用吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": channelId, "enabled": 0 });
		    })
		}

		/* 用户管理启用 */
		function enable(channelId) {
			$.modal.confirm("确认要启用吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": channelId, "enabled": 1 });
		    })
		}
    </script>
</body>
</html>